# Import Google's gdata module.
# Either from standard places or via -gdata option.
#
# Copyright (C) 2010 Yotam Medini <yotam.medini@gmail.com>
#
# This file is part of Gupicasa.
#
# Gupicasa is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Gupicasa is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Gupicasa.  If not, see <http://www.gnu.org/licenses/>.


import sys

try:
    import gdata
    gdata_imported = True
except:
    gdata_imported = False
if not gdata_imported:
    na = len(sys.argv)
    opt_gdata = (sys.argv + ["-gdata"]).index("-gdata")
    if opt_gdata + 1 < na:
        sys.path.append(sys.argv[opt_gdata + 1])
        try:
            import gdata
        except Exception, e:
            sys.stderr.write("Failed to import gdata. %s\n" % e)
            sys.exit(1)
    else:
        sys.stderr.write("Failed to import gdata, try:  -gdata <dir>\n")
        sys.exit(1)
# sys.stderr.write("dir(gdata)=%s\n" % dir(gdata))
# sys.stderr.write("gdata: __builtins__=%s\n" % gdata.__builtins__)
sys.stderr.write("gdata: name=%s, package=%s, path=%s\n" %
                 (gdata.__name__, gdata.__package__, gdata.__path__))


def gdata_module():
    global gdata
    return gdata



